package com.xinlan.imageeditlibrary.editimage.adapter;

import android.graphics.Bitmap;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xinlan.imageeditlibrary.R;

import java.util.ArrayList;

/**
 * @author 关忆北丶
 * @description:
 * @date :2020/9/10 18:45
 */
public class StickerPictureAdapter extends RecyclerView.Adapter<StickerPictureAdapter.StickerPictureHolder> {
    private LayoutInflater mInflater;
    private ArrayList<String> mPathList = new ArrayList<>();
    private OnStickerPictureClickListener mOnStickerPictureClickListener;
    public StickerPictureAdapter(LayoutInflater mInflater) {
        this.mInflater = mInflater;
    }

    public void setStickList(ArrayList<String> pathList) {
        this.mPathList = pathList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public StickerPictureHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new StickerPictureHolder(mInflater.inflate(R.layout.item_stickerpicture, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull StickerPictureHolder stickerPictureHolder, int position) {
        final String path = mPathList.get(position);
        ImageLoader.getInstance().displayImage("assets://" + path,
                stickerPictureHolder.mTvItemPicture);
        stickerPictureHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnStickerPictureClickListener!=null)
                    mOnStickerPictureClickListener.onStickerPicture(path);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mPathList.size();
    }

    public class StickerPictureHolder extends RecyclerView.ViewHolder {

        private ImageView mTvItemPicture;

        public StickerPictureHolder(@NonNull View itemView) {
            super(itemView);
            mTvItemPicture = itemView.findViewById(R.id.tv_item_picture);
        }
    }



    public void setOnStickerPictureClickListener(OnStickerPictureClickListener onStickerPictureClickListener) {
        this.mOnStickerPictureClickListener = onStickerPictureClickListener;
    }

    public interface OnStickerPictureClickListener {
        void onStickerPicture(String assetsPath);
    }

}
